<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-8-18
 * Time: 下午8:07
 */
$_REQUEST['subsite'] = 'backend';
require ('core/shop.php');

if (!isset($_REQUEST['bill_goods_no']) || empty($_REQUEST['bill_goods_no'])) {
    die('缺少参数');
}

$print_goods_array = $G_SHOP->DBCA->stmt_query('SELECT * FROM V_for_qs WHERE bill_goods_no_p = ?', 's', $_REQUEST['bill_goods_no']);
if (!$print_goods_array || empty($print_goods_array[0]->bill_code_p)) {
    die('订单商品[' . $_REQUEST['bill_goods_no'] . ']，数据没有找到');
}
$print_goods_obj = $print_goods_array[0];



//add by 2014-10-27 yim.hu  FUN-BK-0017-生产单中的营养成分表格调整间距 start

// 这里开始是项目截取
$p_ii_p =explode(' ',$print_goods_obj->head_ii_p);
//开始截取字符串
for($i = 0;$i<3;$i++){
	if($i == 0){
		$xiangmu = $p_ii_p[$i];
		continue;
	}
	if($i==1){
		$hanliang1 = substr($p_ii_p[$i],0,strpos($p_ii_p[$i],'/'));
		$hanliang2 = substr($p_ii_p[$i],strpos($p_ii_p[$i],'/')+1);
		continue;	
	}
	if($i==2){
		$cankao1 = substr($p_ii_p[$i],0,strpos($p_ii_p[$i],'%')+1);
		$cankao2 = substr(substr($p_ii_p[$i],strpos($p_ii_p[$i],'值')+3),1);
		continue;		
	}	
}

//这里开始截取dip
$dip = explode(' ',preg_replace('/\s(?=\s)/', '', trim($print_goods_obj->d_i_p)));

for($i = 0;$i<count($dip);$i++){
	
	if($i==0){
		$dip1 = $dip[$i];
		continue;
	}
	if($i==1){
		$dip2 = $dip[$i];
		continue;		
	}
	if($i==2){
		$dip3 = $dip[$i];
		continue;		
	}
}

//这里开始截取diip
$diip = explode(' ',preg_replace('/\s(?=\s)/', '', trim($print_goods_obj->d_ii_p)));

for($i = 0;$i<count($diip);$i++){
	
	if($i==0){
		$diip1 = $diip[$i];
		continue;
	}
	if($i==1){
		$diip2 = $diip[$i];
		continue;		
	}
	if($i==2){
		$diip3 = $diip[$i];
		continue;		
	}
}


//这里开始截取diiip
$diiip = explode(' ',preg_replace('/\s(?=\s)/', '', trim($print_goods_obj->d_iii_p)));
for($i = 0;$i<count($diiip);$i++){	
	if($i==0){
		$diiip1 = $diiip[$i];
		continue;
	}
	if($i==1){
		$diiip2 = $diiip[$i];
		continue;		
	}
	if($i==2){
		$diiip3 = $diiip[$i];
		continue;		
	}
}
//这里开始截取dvp
$dvp = explode(' ',preg_replace('/\s(?=\s)/', '', trim($print_goods_obj->d_v_p)));
for($i = 0;$i<count($dvp);$i++){	
	if($i==0){
		$dvp1 = $dvp[$i];
		continue;
	}
	if($i==1){
		$dvp2 = $dvp[$i];
		continue;		
	}
	if($i==2){
		$dvp3 = $dvp[$i];
		continue;		
	}
}
//这里开始截取divp
$divp = explode(' ',preg_replace('/\s(?=\s)/', '', trim($print_goods_obj->d_iv_p)));
for($i = 0;$i<count($divp);$i++){	
	if($i==0){
		$divp1 = $divp[$i];
		continue;
	}
	if($i==1){
		$divp2 = $divp[$i];
		continue;		
	}
	if($i==2){
		$divp3 = $divp[$i];
		continue;		
	}
}
//这里开始截取dvip
$dvip = explode(' ',preg_replace('/\s(?=\s)/', '', trim($print_goods_obj->d_vi_p)));
for($i = 0;$i<count($dvip);$i++){	
	if($i==0){
		$dvip1 = $dvip[$i];
		continue;
	}
	if($i==1){
		$dvip2 = $dvip[$i];
		continue;		
	}
	if($i==2){
		$dvip3 = $dvip[$i];
		continue;		
	}
}
//add by 2014-10-27 yim.hu  FUN-BK-0017-生产单中的营养成分表格调整间距 end
$print_array = array(
    'bill_goods_no_p' => $print_goods_obj->bill_goods_no_p,
    'bill_code_p' => $print_goods_obj->bill_code_p,
    'print_time_p' => $print_goods_obj->print_time_p,
    'bill_type_h' => $print_goods_obj->bill_type_h,
    'bill_type_p' => $print_goods_obj->bill_type_p,
    'city_dis_btime_p' => $print_goods_obj->city_dis_btime_p,
    'send_dtime_p' => $print_goods_obj->send_dtime_p,
    'qsname_i_p' => $print_goods_obj->qsname_i_p,
    'goods_spec' => $print_goods_obj->goods_spec,
    'fit_normal_p' => $print_goods_obj->fit_normal_p,
    'fit_plus_p' => $print_goods_obj->fit_plus_p,
    'birthday_card_p' => htmlspecialchars($print_goods_obj->birthday_card_p, ENT_QUOTES),
    'cut_p' => $print_goods_obj->cut_p,
    'goods_remark_p' => htmlspecialchars($print_goods_obj->goods_remark_p, ENT_QUOTES),
    'print_num_p' => $print_goods_obj->print_num_p,
    'head_i_p' => $print_goods_obj->head_i_p,
    'head_ii_p' => $print_goods_obj->head_ii_p,
    'd_i_p' => $print_goods_obj->d_i_p,
    'd_ii_p' => $print_goods_obj->d_ii_p,
    'd_iii_p' => $print_goods_obj->d_iii_p,
    'd_iv_p' => $print_goods_obj->d_iv_p,
    'd_v_p' => $print_goods_obj->d_v_p,
    'd_vi_p' => $print_goods_obj->d_vi_p,
    'product_code_p' => $print_goods_obj->product_code_p,
    'product_date_p' => $print_goods_obj->product_date_p,
    'qsname_ii_p' => $print_goods_obj->qsname_ii_p,
    'recipe_p' => $print_goods_obj->recipe_p,
    'weight_p' => $print_goods_obj->weight_p,
    'p_i_p' => $print_goods_obj->p_i_p,
    'p_ii_p' => $print_goods_obj->p_ii_p,
    'p_iii_p' => $print_goods_obj->p_iii_p,
    'p_iv_p' => $print_goods_obj->p_iv_p,
    'p_v_p' => $print_goods_obj->p_v_p,
    'p_vi_p' => $print_goods_obj->p_vi_p,
    'try_eat_p' => $print_goods_obj->try_eat_p,
    'is_zxcard' => $print_goods_obj->is_zxcard,
    'bill_totalAmount' => $print_goods_obj->bill_totalAmount,
    'fit_candle' => $print_goods_obj->fit_candle,
	//add by 2014-10-27 yim.hu  FUN-BK-0017-生产单中的营养成分表格调整间距 start		
	'xiangmu' =>$xiangmu,
	'hanliang1'=>$hanliang1,
	'hanliang2'=>$hanliang2,
	'cankao1' =>$cankao1,	
	'cankao2'=>$cankao2,
	'dip1'=>$dip1,
	'dip2'=>$dip2,
	'dip3'=>$dip3,		
	'diip1'=>$diip1,		
	'diip2'=>$diip2,		
	'diip3'=>$diip3,		
	'diiip1'=>$diiip1,		
	'diiip2'=>$diiip2,
	'diiip3'=>$diiip3,
	'dvp1'=>$dvp1,
	'dvp2'=>$dvp2,
	'dvp3'=>$dvp3,
	'divp1'=>$divp1,
	'divp2'=>$divp2,
	'divp3'=>$divp3,
	'dvip1'=>$dvip1,
	'dvip2'=>$dvip2,
	'dvip3'=>$dvip3,	
	//add by 2014-10-27 yim.hu  FUN-BK-0017-生产单中的营养成分表格调整间距 end
);

$xml_string = "<xml>\n";
$xml_string .="<row>";
foreach($print_array as $key => $val) {
    $xml_string .= "<$key>$val</$key>";
}
$xml_string .="</row>\n";
$xml_string .= "</xml>\n";

//header("gr_zip_type: deflate");                                      //指定压缩方法
//header("gr_zip_size: " . strval(strlen($xml_string)));                    //指定数据的原始长度
//error_log(iconv_get_encoding('internal_encoding'));
//header("gr_zip_encode: " . iconv_get_encoding('internal_encoding'));   //指定数据的编码方式 utf-8 utf-16 ...

//压缩数据并输出
//$compressed = gzdeflate($xml_string);
//echo base64_encode($compressed);

header("Content-Type: text/html; charset=utf-8"); //这里应根据实际运行环境调整，如：utf-8等
echo $xml_string;